{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "\n",
        "<div align=\"center\">\n",
        "  <img src=\"https://github.com/hitsz-ids/synthetic-data-generator/blob/main/assets/sdg_logo.png?raw=true\" width=\"400\" >\n",
        "</div>\n",
        "<div align=\"center\">"
      ],
      "metadata": {
        "id": "vXe3iwJzPK-6"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "\n",
        "\n",
        "\n",
        "\n",
        "# 🚀 Synthetic data generation without Raw Data using LLM\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "The Synthetic Data Generator (SDG) is a specialized framework designed to generate high-quality structured tabular data. It incorporates a wide range of single-table, multi-table data synthesis algorithms and LLM-based synthetic data generation models.\n",
        "\n",
        "Synthetic data, generated by machines using real data, metadata, and algorithms, does not contain any sensitive information, yet it retains the essential characteristics of the original data. There is no direct correlation between synthetic data and real data, making it exempt from privacy regulations such as GDPR and ADPPA. This eliminates the risk of privacy breaches in practical applications."
      ],
      "metadata": {
        "id": "H-I6ZJ6cFwxx"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# install dependencies\n",
        "!pip install sdgx\n",
        "# OR\n",
        "# !pip install git+https://github.com/hitsz-ids/synthetic-data-generator.git"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "dmIUNuTlF2et",
        "outputId": "48c1c8ef-41a0-44ad-deef-a2eaec1695b4"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Collecting sdgx\n",
            "  Downloading sdgx-0.2.0-py3-none-any.whl (216 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m216.7/216.7 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from sdgx) (8.1.7)\n",
            "Requirement already satisfied: cloudpickle in /usr/local/lib/python3.10/dist-packages (from sdgx) (2.2.1)\n",
            "Collecting faker>=10 (from sdgx)\n",
            "  Downloading Faker-25.8.0-py3-none-any.whl (1.8 MB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m12.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: importlib-metadata in /usr/local/lib/python3.10/dist-packages (from sdgx) (7.1.0)\n",
            "Collecting loguru (from sdgx)\n",
            "  Downloading loguru-0.7.2-py3-none-any.whl (62 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.5/62.5 kB\u001b[0m \u001b[31m7.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from sdgx) (3.7.1)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from sdgx) (1.25.2)\n",
            "Collecting openai>=1.10.0 (from sdgx)\n",
            "  Downloading openai-1.33.0-py3-none-any.whl (325 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m325.5/325.5 kB\u001b[0m \u001b[31m13.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from sdgx) (2.0.3)\n",
            "Requirement already satisfied: pluggy in /usr/local/lib/python3.10/dist-packages (from sdgx) (1.5.0)\n",
            "Requirement already satisfied: pyarrow in /usr/local/lib/python3.10/dist-packages (from sdgx) (14.0.2)\n",
            "Requirement already satisfied: pydantic>=2 in /usr/local/lib/python3.10/dist-packages (from sdgx) (2.7.3)\n",
            "Requirement already satisfied: pyyaml in /usr/local/lib/python3.10/dist-packages (from sdgx) (6.0.1)\n",
            "Requirement already satisfied: scikit-learn<2,>=0.24 in /usr/local/lib/python3.10/dist-packages (from sdgx) (1.2.2)\n",
            "Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from sdgx) (1.11.4)\n",
            "Collecting table-evaluator (from sdgx)\n",
            "  Downloading table_evaluator-1.6.1-py3-none-any.whl (22 kB)\n",
            "Requirement already satisfied: torch>=2 in /usr/local/lib/python3.10/dist-packages (from sdgx) (2.3.0+cu121)\n",
            "Requirement already satisfied: torchvision in /usr/local/lib/python3.10/dist-packages (from sdgx) (0.18.0+cu121)\n",
            "Requirement already satisfied: python-dateutil>=2.4 in /usr/local/lib/python3.10/dist-packages (from faker>=10->sdgx) (2.8.2)\n",
            "Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.10.0->sdgx) (3.7.1)\n",
            "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from openai>=1.10.0->sdgx) (1.7.0)\n",
            "Collecting httpx<1,>=0.23.0 (from openai>=1.10.0->sdgx)\n",
            "  Downloading httpx-0.27.0-py3-none-any.whl (75 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m8.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from openai>=1.10.0->sdgx) (1.3.1)\n",
            "Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.10/dist-packages (from openai>=1.10.0->sdgx) (4.66.4)\n",
            "Requirement already satisfied: typing-extensions<5,>=4.7 in /usr/local/lib/python3.10/dist-packages (from openai>=1.10.0->sdgx) (4.12.1)\n",
            "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2->sdgx) (0.7.0)\n",
            "Requirement already satisfied: pydantic-core==2.18.4 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2->sdgx) (2.18.4)\n",
            "Requirement already satisfied: joblib>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from scikit-learn<2,>=0.24->sdgx) (1.4.2)\n",
            "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn<2,>=0.24->sdgx) (3.5.0)\n",
            "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch>=2->sdgx) (3.14.0)\n",
            "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch>=2->sdgx) (1.12.1)\n",
            "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=2->sdgx) (3.3)\n",
            "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=2->sdgx) (3.1.4)\n",
            "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch>=2->sdgx) (2023.6.0)\n",
            "Collecting nvidia-cuda-nvrtc-cu12==12.1.105 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)\n",
            "Collecting nvidia-cuda-runtime-cu12==12.1.105 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)\n",
            "Collecting nvidia-cuda-cupti-cu12==12.1.105 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)\n",
            "Collecting nvidia-cudnn-cu12==8.9.2.26 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_cudnn_cu12-8.9.2.26-py3-none-manylinux1_x86_64.whl (731.7 MB)\n",
            "Collecting nvidia-cublas-cu12==12.1.3.1 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)\n",
            "Collecting nvidia-cufft-cu12==11.0.2.54 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl (121.6 MB)\n",
            "Collecting nvidia-curand-cu12==10.3.2.106 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl (56.5 MB)\n",
            "Collecting nvidia-cusolver-cu12==11.4.5.107 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl (124.2 MB)\n",
            "Collecting nvidia-cusparse-cu12==12.1.0.106 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl (196.0 MB)\n",
            "Collecting nvidia-nccl-cu12==2.20.5 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl (176.2 MB)\n",
            "Collecting nvidia-nvtx-cu12==12.1.105 (from torch>=2->sdgx)\n",
            "  Using cached nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (99 kB)\n",
            "Requirement already satisfied: triton==2.3.0 in /usr/local/lib/python3.10/dist-packages (from torch>=2->sdgx) (2.3.0)\n",
            "Collecting nvidia-nvjitlink-cu12 (from nvidia-cusolver-cu12==11.4.5.107->torch>=2->sdgx)\n",
            "  Downloading nvidia_nvjitlink_cu12-12.5.40-py3-none-manylinux2014_x86_64.whl (21.3 MB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.3/21.3 MB\u001b[0m \u001b[31m54.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.10/dist-packages (from importlib-metadata->sdgx) (3.19.1)\n",
            "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->sdgx) (1.2.1)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->sdgx) (0.12.1)\n",
            "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->sdgx) (4.53.0)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->sdgx) (1.4.5)\n",
            "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->sdgx) (24.0)\n",
            "Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->sdgx) (9.4.0)\n",
            "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->sdgx) (3.1.2)\n",
            "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->sdgx) (2023.4)\n",
            "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->sdgx) (2024.1)\n",
            "Requirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from table-evaluator->sdgx) (5.9.5)\n",
            "Collecting dython==0.7.3 (from table-evaluator->sdgx)\n",
            "  Downloading dython-0.7.3-py3-none-any.whl (23 kB)\n",
            "Requirement already satisfied: seaborn in /usr/local/lib/python3.10/dist-packages (from table-evaluator->sdgx) (0.13.1)\n",
            "Collecting scikit-plot>=0.3.7 (from dython==0.7.3->table-evaluator->sdgx)\n",
            "  Downloading scikit_plot-0.3.7-py3-none-any.whl (33 kB)\n",
            "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai>=1.10.0->sdgx) (3.7)\n",
            "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->openai>=1.10.0->sdgx) (1.2.1)\n",
            "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->openai>=1.10.0->sdgx) (2024.6.2)\n",
            "Collecting httpcore==1.* (from httpx<1,>=0.23.0->openai>=1.10.0->sdgx)\n",
            "  Downloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m12.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hCollecting h11<0.15,>=0.13 (from httpcore==1.*->httpx<1,>=0.23.0->openai>=1.10.0->sdgx)\n",
            "  Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m9.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.4->faker>=10->sdgx) (1.16.0)\n",
            "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=2->sdgx) (2.1.5)\n",
            "Requirement already satisfied: mpmath<1.4.0,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy->torch>=2->sdgx) (1.3.0)\n",
            "Installing collected packages: nvidia-nvtx-cu12, nvidia-nvjitlink-cu12, nvidia-nccl-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, loguru, h11, nvidia-cusparse-cu12, nvidia-cudnn-cu12, httpcore, faker, scikit-plot, nvidia-cusolver-cu12, httpx, openai, dython, table-evaluator, sdgx\n",
            "Successfully installed dython-0.7.3 faker-25.8.0 h11-0.14.0 httpcore-1.0.5 httpx-0.27.0 loguru-0.7.2 nvidia-cublas-cu12-12.1.3.1 nvidia-cuda-cupti-cu12-12.1.105 nvidia-cuda-nvrtc-cu12-12.1.105 nvidia-cuda-runtime-cu12-12.1.105 nvidia-cudnn-cu12-8.9.2.26 nvidia-cufft-cu12-11.0.2.54 nvidia-curand-cu12-10.3.2.106 nvidia-cusolver-cu12-11.4.5.107 nvidia-cusparse-cu12-12.1.0.106 nvidia-nccl-cu12-2.20.5 nvidia-nvjitlink-cu12-12.5.40 nvidia-nvtx-cu12-12.1.105 openai-1.33.0 scikit-plot-0.3.7 sdgx-0.2.0 table-evaluator-1.6.1\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from sdgx.models.LLM.single_table.gpt import *\n",
        "class SingleTableGLMModel(SingleTableGPTModel):\n",
        "\n",
        "    def ask_gpt(self, question, model=None):\n",
        "        \"\"\"\n",
        "        Sends a question to the GPT model.\n",
        "\n",
        "        Args:\n",
        "            question (str): The question to ask.\n",
        "            model (str): The GPT model to use. Defaults to None.\n",
        "\n",
        "        Returns:\n",
        "            str: The response from the GPT model.\n",
        "\n",
        "        Raises:\n",
        "            SynthesizerInitError: If the check method fails.\n",
        "        \"\"\"\n",
        "        self.check()\n",
        "        api_key = self.openai_API_key\n",
        "        if model:\n",
        "            model = model\n",
        "        else:\n",
        "            model = self.gpt_model\n",
        "        openai.api_key = api_key\n",
        "        client = openai.OpenAI(base_url=self.openai_API_url,\n",
        "                               api_key=api_key)\n",
        "        logger.info(f\"Ask GPT with temperature = {self.temperature}.\")\n",
        "        response = client.chat.completions.create(\n",
        "            model=model,\n",
        "            messages=[\n",
        "                {\n",
        "                    \"role\": \"user\",\n",
        "                    \"content\": question,\n",
        "                },\n",
        "            ],\n",
        "\n",
        "            temperature=self.temperature,\n",
        "            max_tokens=self.max_tokens,\n",
        "            timeout=self.timeout,\n",
        "        )\n",
        "        logger.info(\"Ask GPT Finished.\")\n",
        "        # store response\n",
        "        self._responses.append(response)\n",
        "        # return the content of the gpt response\n",
        "        return response.choices[0].message.content"
      ],
      "metadata": {
        "id": "MP-cOagfMwXx"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "We demonstrate with a single table simulation example.\n",
        "\n",
        "# LLM-integrated synthetic data generation\n",
        "\n",
        "For a long time, LLM has been used to understand and generate various types of data.\n",
        "\n",
        "In fact, LLM also has certain capabilities in tabular data generation. LLM has some abilities that cannot be achieved by traditional (GAN-based models or statistical models) .\n",
        "\n"
      ],
      "metadata": {
        "id": "BKSWvnJgF3h7"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# please set your GLM4 key here:\n",
        "\n",
        "GLM4_AI_KEY = {YOUR_KEY}\n",
        "GLM4_AI_BASE = 'https://open.bigmodel.cn/api/paas/v4/'"
      ],
      "metadata": {
        "id": "o_mw9FeNPTcb"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# import packages\n",
        "\n",
        "import pandas as pd\n",
        "from sdgx.utils import download_demo_data\n",
        "from sdgx.data_models.metadata import Metadata\n",
        "from sdgx.models.LLM.single_table.gpt import SingleTableGPTModel\n",
        "\n",
        "# read the demo data\n",
        "# currently we use the well-known adult dataset as a example\n",
        "data_path = download_demo_data()\n",
        "df = pd.read_csv(data_path)\n",
        "metadata = Metadata.from_dataframe(df)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "QLTmGyofF3V8",
        "outputId": "5b1a3394-6e63-4258-f980-47f42d41bcb2"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "\u001b[32m2024-06-12 02:08:49.329\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.utils\u001b[0m:\u001b[36mdownload_demo_data\u001b[0m:\u001b[36m68\u001b[0m - \u001b[1mDownloading demo data from github data source to /content/dataset/adult.csv\u001b[0m\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "\n",
        "# Synthetic data generation without Data\n",
        "\n",
        "\n",
        "Our `sdgx.models.LLM.single_table.gpt.SingleTableGPTModel` implements “Synthetic data generation without Raw Data”.\n",
        "\n",
        "No training data is required, synthetic data can be generated based on metadata data.\n",
        "\n",
        "![LLM_Case_1](https://github.com/hitsz-ids/synthetic-data-generator/blob/main/assets/LLM_Case_2.gif?raw=true)"
      ],
      "metadata": {
        "id": "TAbHCsEXJcfZ"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "model = SingleTableGLMModel()\n",
        "model.set_openAI_settings(GLM4_AI_BASE, GLM4_AI_KEY)\n",
        "model.gpt_model = \"glm-4\""
      ],
      "metadata": {
        "id": "e9cJ79xdVqek"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "model.fit(metadata)\n",
        "# this may take a while\n",
        "model.sample(30, off_table_features = ['has_car'])"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 737
        },
        "id": "MlnE68SvOKb0",
        "outputId": "f746a1b7-765e-4b10-9afd-75199b28022d"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "\u001b[32m2024-06-12 02:10:53.133\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.single_table.gpt\u001b[0m:\u001b[36m_fit_with_metadata\u001b[0m:\u001b[36m228\u001b[0m - \u001b[1mFitting model with metadata...\u001b[0m\n",
            "\u001b[32m2024-06-12 02:10:53.135\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.single_table.gpt\u001b[0m:\u001b[36m_fit_with_metadata\u001b[0m:\u001b[36m232\u001b[0m - \u001b[1mFitting model with metadata... Finished.\u001b[0m\n",
            "\u001b[32m2024-06-12 02:10:53.137\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.single_table.gpt\u001b[0m:\u001b[36msample\u001b[0m:\u001b[36m385\u001b[0m - \u001b[1mSampling use GPT model ...\u001b[0m\n",
            "\u001b[32m2024-06-12 02:10:53.138\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.single_table.gpt\u001b[0m:\u001b[36m_sample_with_metadata\u001b[0m:\u001b[36m446\u001b[0m - \u001b[1mSampling with metadata.\u001b[0m\n",
            "\u001b[32m2024-06-12 02:10:53.140\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.base\u001b[0m:\u001b[36m_form_dataset_description\u001b[0m:\u001b[36m122\u001b[0m - \u001b[1mNo dataset_description given in current model.\u001b[0m\n",
            "\u001b[32m2024-06-12 02:10:53.142\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.base\u001b[0m:\u001b[36m_form_message_with_offtable_features\u001b[0m:\u001b[36m108\u001b[0m - \u001b[1mNo off_table_feature needed in current model.\u001b[0m\n",
            "\u001b[32m2024-06-12 02:10:53.214\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36mask_gpt\u001b[0m:\u001b[36m27\u001b[0m - \u001b[1mAsk GPT with temperature = 0.1.\u001b[0m\n",
            "\u001b[32m2024-06-12 02:14:35.819\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36mask_gpt\u001b[0m:\u001b[36m41\u001b[0m - \u001b[1mAsk GPT Finished.\u001b[0m\n",
            "\u001b[32m2024-06-12 02:14:35.828\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.single_table.gpt\u001b[0m:\u001b[36mextract_samples_from_response\u001b[0m:\u001b[36m357\u001b[0m - \u001b[1mExtracting samples from response ...\u001b[0m\n",
            "\u001b[32m2024-06-12 02:14:35.838\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.single_table.gpt\u001b[0m:\u001b[36mextract_samples_from_response\u001b[0m:\u001b[36m369\u001b[0m - \u001b[1mExtracting samples from response ... Finished, 10 extracted.\u001b[0m\n",
            "\u001b[32m2024-06-12 02:14:35.850\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36msdgx.models.LLM.single_table.gpt\u001b[0m:\u001b[36msample\u001b[0m:\u001b[36m395\u001b[0m - \u001b[1mSampling use GPT model ... Finished.\u001b[0m\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "  educational-num      marital-status native-country capital-loss  gender  \\\n",
              "0              10  Married-civ-spouse  United-States            0    Male   \n",
              "1              13       Never-married         Mexico         1500  Female   \n",
              "2               9            Divorced    Philippines            0    Male   \n",
              "3              12   Married-AF-spouse        Germany          500  Female   \n",
              "4               8           Separated         Canada         2000    Male   \n",
              "5              11             Widowed          India            0  Female   \n",
              "6               7  Married-civ-spouse  United-States         1000    Male   \n",
              "7              14       Never-married  United-States            0  Female   \n",
              "8               6            Divorced          Italy         1500    Male   \n",
              "9              13   Married-AF-spouse  United-States            0  Female   \n",
              "\n",
              "  hours-per-week income     education  fnlwgt         workclass age  \\\n",
              "0             40  <=50K     Bachelors  205263           Private  45   \n",
              "1             45  <=50K       Masters  189284  Self-emp-not-inc  32   \n",
              "2             60   >50K       HS-grad  267450       Federal-gov  38   \n",
              "3             35  <=50K     Assoc-voc  223434         Local-gov  29   \n",
              "4             55  <=50K  Some-college  336924         State-gov  41   \n",
              "5             20  <=50K     Doctorate  278844      Self-emp-inc  56   \n",
              "6             30  <=50K     Bachelors  147115           Private  36   \n",
              "7             50   >50K   Prof-school  324442  Self-emp-not-inc  28   \n",
              "8             65   >50K       HS-grad  212323       Federal-gov  42   \n",
              "9             38  <=50K     Assoc-voc  198234         Local-gov  31   \n",
              "\n",
              "                 race    relationship capital-gain         occupation  \n",
              "0               White         Husband         1000    Exec-managerial  \n",
              "1            Hispanic       Own-child            0     Prof-specialty  \n",
              "2  Asian-Pac-Islander       Unmarried         2000    Protective-serv  \n",
              "3               White            Wife            0       Tech-support  \n",
              "4               Black  Other-relative         1500              Sales  \n",
              "5  Asian-Pac-Islander   Not-in-family         3000     Prof-specialty  \n",
              "6               White         Husband            0       Craft-repair  \n",
              "7               White       Own-child         2500    Exec-managerial  \n",
              "8               White       Unmarried          500       Adm-clerical  \n",
              "9               Black            Wife         1000  Handlers-cleaners  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-ee786ced-5110-40de-847e-782b6a860c86\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>educational-num</th>\n",
              "      <th>marital-status</th>\n",
              "      <th>native-country</th>\n",
              "      <th>capital-loss</th>\n",
              "      <th>gender</th>\n",
              "      <th>hours-per-week</th>\n",
              "      <th>income</th>\n",
              "      <th>education</th>\n",
              "      <th>fnlwgt</th>\n",
              "      <th>workclass</th>\n",
              "      <th>age</th>\n",
              "      <th>race</th>\n",
              "      <th>relationship</th>\n",
              "      <th>capital-gain</th>\n",
              "      <th>occupation</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>10</td>\n",
              "      <td>Married-civ-spouse</td>\n",
              "      <td>United-States</td>\n",
              "      <td>0</td>\n",
              "      <td>Male</td>\n",
              "      <td>40</td>\n",
              "      <td>&lt;=50K</td>\n",
              "      <td>Bachelors</td>\n",
              "      <td>205263</td>\n",
              "      <td>Private</td>\n",
              "      <td>45</td>\n",
              "      <td>White</td>\n",
              "      <td>Husband</td>\n",
              "      <td>1000</td>\n",
              "      <td>Exec-managerial</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>13</td>\n",
              "      <td>Never-married</td>\n",
              "      <td>Mexico</td>\n",
              "      <td>1500</td>\n",
              "      <td>Female</td>\n",
              "      <td>45</td>\n",
              "      <td>&lt;=50K</td>\n",
              "      <td>Masters</td>\n",
              "      <td>189284</td>\n",
              "      <td>Self-emp-not-inc</td>\n",
              "      <td>32</td>\n",
              "      <td>Hispanic</td>\n",
              "      <td>Own-child</td>\n",
              "      <td>0</td>\n",
              "      <td>Prof-specialty</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>9</td>\n",
              "      <td>Divorced</td>\n",
              "      <td>Philippines</td>\n",
              "      <td>0</td>\n",
              "      <td>Male</td>\n",
              "      <td>60</td>\n",
              "      <td>&gt;50K</td>\n",
              "      <td>HS-grad</td>\n",
              "      <td>267450</td>\n",
              "      <td>Federal-gov</td>\n",
              "      <td>38</td>\n",
              "      <td>Asian-Pac-Islander</td>\n",
              "      <td>Unmarried</td>\n",
              "      <td>2000</td>\n",
              "      <td>Protective-serv</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>12</td>\n",
              "      <td>Married-AF-spouse</td>\n",
              "      <td>Germany</td>\n",
              "      <td>500</td>\n",
              "      <td>Female</td>\n",
              "      <td>35</td>\n",
              "      <td>&lt;=50K</td>\n",
              "      <td>Assoc-voc</td>\n",
              "      <td>223434</td>\n",
              "      <td>Local-gov</td>\n",
              "      <td>29</td>\n",
              "      <td>White</td>\n",
              "      <td>Wife</td>\n",
              "      <td>0</td>\n",
              "      <td>Tech-support</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>8</td>\n",
              "      <td>Separated</td>\n",
              "      <td>Canada</td>\n",
              "      <td>2000</td>\n",
              "      <td>Male</td>\n",
              "      <td>55</td>\n",
              "      <td>&lt;=50K</td>\n",
              "      <td>Some-college</td>\n",
              "      <td>336924</td>\n",
              "      <td>State-gov</td>\n",
              "      <td>41</td>\n",
              "      <td>Black</td>\n",
              "      <td>Other-relative</td>\n",
              "      <td>1500</td>\n",
              "      <td>Sales</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>11</td>\n",
              "      <td>Widowed</td>\n",
              "      <td>India</td>\n",
              "      <td>0</td>\n",
              "      <td>Female</td>\n",
              "      <td>20</td>\n",
              "      <td>&lt;=50K</td>\n",
              "      <td>Doctorate</td>\n",
              "      <td>278844</td>\n",
              "      <td>Self-emp-inc</td>\n",
              "      <td>56</td>\n",
              "      <td>Asian-Pac-Islander</td>\n",
              "      <td>Not-in-family</td>\n",
              "      <td>3000</td>\n",
              "      <td>Prof-specialty</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>7</td>\n",
              "      <td>Married-civ-spouse</td>\n",
              "      <td>United-States</td>\n",
              "      <td>1000</td>\n",
              "      <td>Male</td>\n",
              "      <td>30</td>\n",
              "      <td>&lt;=50K</td>\n",
              "      <td>Bachelors</td>\n",
              "      <td>147115</td>\n",
              "      <td>Private</td>\n",
              "      <td>36</td>\n",
              "      <td>White</td>\n",
              "      <td>Husband</td>\n",
              "      <td>0</td>\n",
              "      <td>Craft-repair</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>14</td>\n",
              "      <td>Never-married</td>\n",
              "      <td>United-States</td>\n",
              "      <td>0</td>\n",
              "      <td>Female</td>\n",
              "      <td>50</td>\n",
              "      <td>&gt;50K</td>\n",
              "      <td>Prof-school</td>\n",
              "      <td>324442</td>\n",
              "      <td>Self-emp-not-inc</td>\n",
              "      <td>28</td>\n",
              "      <td>White</td>\n",
              "      <td>Own-child</td>\n",
              "      <td>2500</td>\n",
              "      <td>Exec-managerial</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>6</td>\n",
              "      <td>Divorced</td>\n",
              "      <td>Italy</td>\n",
              "      <td>1500</td>\n",
              "      <td>Male</td>\n",
              "      <td>65</td>\n",
              "      <td>&gt;50K</td>\n",
              "      <td>HS-grad</td>\n",
              "      <td>212323</td>\n",
              "      <td>Federal-gov</td>\n",
              "      <td>42</td>\n",
              "      <td>White</td>\n",
              "      <td>Unmarried</td>\n",
              "      <td>500</td>\n",
              "      <td>Adm-clerical</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>13</td>\n",
              "      <td>Married-AF-spouse</td>\n",
              "      <td>United-States</td>\n",
              "      <td>0</td>\n",
              "      <td>Female</td>\n",
              "      <td>38</td>\n",
              "      <td>&lt;=50K</td>\n",
              "      <td>Assoc-voc</td>\n",
              "      <td>198234</td>\n",
              "      <td>Local-gov</td>\n",
              "      <td>31</td>\n",
              "      <td>Black</td>\n",
              "      <td>Wife</td>\n",
              "      <td>1000</td>\n",
              "      <td>Handlers-cleaners</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-ee786ced-5110-40de-847e-782b6a860c86')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-ee786ced-5110-40de-847e-782b6a860c86 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-ee786ced-5110-40de-847e-782b6a860c86');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-301224d1-d64f-4538-8ccc-e1444d43e879\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-301224d1-d64f-4538-8ccc-e1444d43e879')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-301224d1-d64f-4538-8ccc-e1444d43e879 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "dataframe",
              "summary": "{\n  \"name\": \"model\",\n  \"rows\": 10,\n  \"fields\": [\n    {\n      \"column\": \"educational-num\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 9,\n        \"samples\": [\n          \"14\",\n          \"13\",\n          \"11\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"marital-status\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 6,\n        \"samples\": [\n          \"Married-civ-spouse\",\n          \"Never-married\",\n          \"Widowed\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"native-country\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 7,\n        \"samples\": [\n          \"United-States\",\n          \"Mexico\",\n          \"India\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"capital-loss\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          \"1500\",\n          \"1000\",\n          \"500\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"gender\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 2,\n        \"samples\": [\n          \"Female\",\n          \"Male\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"hours-per-week\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 10,\n        \"samples\": [\n          \"65\",\n          \"45\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"income\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 2,\n        \"samples\": [\n          \">50K\",\n          \"<=50K\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"education\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 7,\n        \"samples\": [\n          \"Bachelors\",\n          \"Masters\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"fnlwgt\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 10,\n        \"samples\": [\n          \"212323\",\n          \"189284\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"workclass\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 6,\n        \"samples\": [\n          \"Private\",\n          \"Self-emp-not-inc\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"age\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 10,\n        \"samples\": [\n          \"42\",\n          \"32\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"race\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 4,\n        \"samples\": [\n          \"Hispanic\",\n          \"Black\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"relationship\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 6,\n        \"samples\": [\n          \"Husband\",\n          \"Own-child\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"capital-gain\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 7,\n        \"samples\": [\n          \"1000\",\n          \"0\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"occupation\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 8,\n        \"samples\": [\n          \"Prof-specialty\",\n          \"Craft-repair\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}"
            }
          },
          "metadata": {},
          "execution_count": 15
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "View the original information returned by gpt through the `_responses` attribute."
      ],
      "metadata": {
        "id": "3rFdzkvarCkN"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "model._responses"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "o_22u0O5Vnor",
        "outputId": "46af595b-a4d9-4b49-debd-2d16290cc34d"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[ChatCompletion(id='8741737668587097609', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=\"Here are 30 synthetic data samples based on the provided column headers:\\n\\n1. educational-num is 10, marital-status is Married-civ-spouse, native-country is United-States, capital-loss is 0, gender is Male, hours-per-week is 40, income is <=50K, education is Bachelors, fnlwgt is 205263, workclass is Private, age is 45, race is White, relationship is Husband, capital-gain is 1000, occupation is Exec-managerial\\n2. educational-num is 13, marital-status is Never-married, native-country is Mexico, capital-loss is 1500, gender is Female, hours-per-week is 45, income is <=50K, education is Masters, fnlwgt is 189284, workclass is Self-emp-not-inc, age is 32, race is Hispanic, relationship is Own-child, capital-gain is 0, occupation is Prof-specialty\\n3. educational-num is 9, marital-status is Divorced, native-country is Philippines, capital-loss is 0, gender is Male, hours-per-week is 60, income is >50K, education is HS-grad, fnlwgt is 267450, workclass is Federal-gov, age is 38, race is Asian-Pac-Islander, relationship is Unmarried, capital-gain is 2000, occupation is Protective-serv\\n4. educational-num is 12, marital-status is Married-AF-spouse, native-country is Germany, capital-loss is 500, gender is Female, hours-per-week is 35, income is <=50K, education is Assoc-voc, fnlwgt is 223434, workclass is Local-gov, age is 29, race is White, relationship is Wife, capital-gain is 0, occupation is Tech-support\\n5. educational-num is 8, marital-status is Separated, native-country is Canada, capital-loss is 2000, gender is Male, hours-per-week is 55, income is <=50K, education is Some-college, fnlwgt is 336924, workclass is State-gov, age is 41, race is Black, relationship is Other-relative, capital-gain is 1500, occupation is Sales\\n6. educational-num is 11, marital-status is Widowed, native-country is India, capital-loss is 0, gender is Female, hours-per-week is 20, income is <=50K, education is Doctorate, fnlwgt is 278844, workclass is Self-emp-inc, age is 56, race is Asian-Pac-Islander, relationship is Not-in-family, capital-gain is 3000, occupation is Prof-specialty\\n7. educational-num is 7, marital-status is Married-civ-spouse, native-country is United-States, capital-loss is 1000, gender is Male, hours-per-week is 30, income is <=50K, education is Bachelors, fnlwgt is 147115, workclass is Private, age is 36, race is White, relationship is Husband, capital-gain is 0, occupation is Craft-repair\\n8. educational-num is 14, marital-status is Never-married, native-country is United-States, capital-loss is 0, gender is Female, hours-per-week is 50, income is >50K, education is Prof-school, fnlwgt is 324442, workclass is Self-emp-not-inc, age is 28, race is White, relationship is Own-child, capital-gain is 2500, occupation is Exec-managerial\\n9. educational-num is 6, marital-status is Divorced, native-country is Italy, capital-loss is 1500, gender is Male, hours-per-week is 65, income is >50K, education is HS-grad, fnlwgt is 212323, workclass is Federal-gov, age is 42, race is White, relationship is Unmarried, capital-gain is 500, occupation is Adm-clerical\\n10. educational-num is 13, marital-status is Married-AF-spouse, native-country is United-States, capital-loss is 0, gender is Female, hours-per-week is 38, income is <=50K, education is Assoc-voc, fnlwgt is 198234, workclass is Local-gov, age is 31, race is Black, relationship is Wife, capital-gain is 1000, occupation is Handlers-cleaners\\n\\n... and so on for a total of 30 data samples. Due to the length of the requested output, I've provided the first 10 samples. If you need the remaining 20, please let me know!\", role='assistant', function_call=None, tool_calls=None))], created=1718158475, model='glm-4', object=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=1010, prompt_tokens=267, total_tokens=1277), request_id='8741737668587097609')]"
            ]
          },
          "metadata": {},
          "execution_count": 16
        }
      ]
    }
  ]
}
